/*eslint-disable*/
const state = {
  tabRoutes: []
}

// getters
const getters = {
  getTabRoutes: state => state.tabRoutes,
  getTabRoutesForString: state => {
    return state.tabRoutes.map(v => v.name).join(',')
  }
}

// mutations
const mutations = {
  /**
   * @param: {Object}
     * @param: {String} type: 添加还是删除
     * @param: {Object} obj
   */
  setTabRoutes(state, { obj, type }) {
    if (type === 'clear') {
      state.tabRoutes = []
      return
    }
    // 判断是否存在此路由 tab
    const isHaveRouterTab = state.tabRoutes.some(v => {
      return v.name === obj.name
    })
    if (type === 'add' && !isHaveRouterTab) {
      state.tabRoutes.push(obj)
    } else if (type === 'remove') {
      // 删除
      state.tabRoutes = state.tabRoutes.filter(v => v.name !== obj.name)
    }
  }

}

export default {
  state,
  getters,
  mutations
}